<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" th:href="@{/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/themes/default.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <script th:src="@{/js/lay-config.js}" charset="utf-8"></script>
    <script th:src="@{/js/jquery-3.3.1.min.js}" charset="utf-8"></script>
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">角色名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="角色名不能为空" placeholder="请输入角色名" value="" class="layui-input">
            <tip>填写角色名称。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认添加</button>
        </div>
    </div>
</div>

<script th:inline="javascript">
    layui.use(['form'], function () {
        var form = layui.form
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                type: "POST",
                url: "/role",
                data: data.field,
                beforeSend: function() {
                    layer.msg("正在处理...")
                },
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.smg, {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        },function () {
                            //关闭窗口,刷新数据表格
                            parent.refreshTable();//调用父类方法重新加载
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    } else {
                        layer.msg(data.message);
                    }
                },
            });
        });
    });
</script>

</body>
</html>